﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="__ADMIN__/static/h-ui.admin/css/style.css" />
<title>数据库备份</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 数据库管理 <span class="c-gray en">&gt;</span> 数据库备份 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="6" >自动备份  {if $type['type']==1}<span class="label label-success radius" style="cursor: pointer" onclick="stop(this,2)">已启动</span>{elseif $type['type']==2}<span class="label radius" onclick="stop(this,1)" style="cursor: pointer">已禁用</span>{/if}<a style="margin: 0 0 0 50px" href="javascript:;" onclick="shezhi('备份设置','{:url("database/edit")}')">备份设置</a></th>
			</tr>
			<tr class="text-c">
				<th width="25"></th>
				<th>备份时间</th>
				<th>备份路径</th>
				<th>备份类型</th>
				<th>备注</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		{foreach $backups as $value}
			<tr class="text-c">
				<td><input type="checkbox" value="{$value['id']}" name=""></td>
				<td>{$value['create_time']|date='Y-m-d H:i:s'}</td>
				<td style="width: 300px">{$value['url']}</td>
				<td>
					{if $value['type']==1}
					自动
					{else}
					手动
					{/if}
				</td>
				<td>{$value['remarks']}</td>
				<td><button class="layui-btn layui-btn-sm" onclick="huanyuan('{$value['id']}')">还原</button><button onclick="shanc('{$value['id']}')">删除</button><button  onclick="xiazai('{$value['id']}')">下载</button></td>
			</tr>
		{/foreach}
		</tbody>
	</table>
	<div style="text-align: center;margin: 20px">
		<a href="javascript:;" onclick="beifen()" class="btn btn-primary radius">
			手动备份
		</a>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__ADMIN__/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__ADMIN__/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__ADMIN__/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="__ADMIN__/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__ADMIN__/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="__ADMIN__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="__ADMIN__/lib/laypage/1.2/laypage.js"></script>
<script src="__ADMIN__/layui/layui.all.js"></script>
<script type="text/javascript" src="__ADMIN__/js/maowenke.js"></script>
<script type="text/javascript">
	function stop(obj,str) {
		ajaxUpdate('{:url("database/showzbf")}',{data:str},'true','post',function (data) {
			if(data==1){
			    if(str==1){
			        $(obj).prop('class','label label-success radius');
			        $(obj).text('已启用');
			        $(obj).attr('onclick','stop(this,2)');
				}else{
                    $(obj).prop('class','label radius');
                    $(obj).text('已禁用');
                    $(obj).attr('onclick','stop(this,1)');
				}
			}else{
			    layer.msg(data);
			}
        })
    }
	function shezhi(title,url) {
		layer_show(title,url,800,500);
    }
	/**还原
	 */
	function huanyuan($id) {
	    var index;
        var indexs = layer.confirm('确定要还原吗？',{btn:['确定','取消']},function () {

            ajaxgo('{:url("database/huanyuan")}',{id:$id},function () {
                index = layer.load(0, {shade: false});
                layer.close(indexs);
            },function (data) {
                console.log(data);
                if(data==1){
                    layer.msg('还原成功');
                    setTimeout(function () {
                        location.reload();
                    },1000);
                }
            },function () {
                layer.close(index);
            });
        });
    }
	/**删除备份表
	 */
	function shanc($id) {
        layer.confirm('确定要删除吗？',{btn:['确定','取消']},function () {
            ajaxUpdate('{:url("database/del")}',{id:$id},'true','post',function (data) {
                if(data==1){
                    layer.msg('删除成功');
                    setTimeout(function () {
						location.reload();
                    },1000)
				}else{
                    layer.msg(data);
				}
            })
        });
    }
	/**下载备份文件的函数
	 */
	function xiazai($id) {
        var $eleForm = $("<form method='get'></form>");
        $eleForm.attr("action","/admin/database/xiazai/id/"+$id);
        $(document.body).append($eleForm);
        //提交表单，实现下载
        $eleForm.submit();
    }
    /**手动备份函数
	 */
	function beifen() {
        layer.prompt({title: '输入备注，并确认', formType: 2}, function(pass, index){
            ajaxUpdate('{:url("database/beifen")}',{beizhu:pass},'true','post',function (data) {
                 console.log(data);
                if(data==1){
                    layer.msg('备份成功');
                    setTimeout(function () {
                        location.reload();
                    },1000);
                }else {
                    layer.msg(data);
                }
            })
        });
    }

</script>
</body>
</html>